//
//  LGServiceOrderDetailController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/28.
//  服务包-订单详情

#import "LGServiceOrderDetailController.h"
#import "LGOrderUserInfoView.h"
#import "LGServiceOrderView.h"

@interface LGServiceOrderDetailController ()
/**   */
@property (nonatomic , strong)UIScrollView *scrollView;
/**   */
@property (nonatomic , strong)UIImageView *statusView;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIButton *typeButton;
/**   */
@property (nonatomic , strong)LGOrderUserInfoView *userView;
/**   */
@property (nonatomic , strong)LGServiceOrderView *serviceView;
/**   */
@property (nonatomic , strong)LGServiceOrderView *orderView;
/**   */
@property (nonatomic , strong)LGServiceOrderView *refundView;

@end

@implementation LGServiceOrderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"订单详情";
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.statusView];
    [self.scrollView addSubview:self.statusLabel];
    [self.scrollView addSubview:self.typeButton];
    [self.scrollView addSubview:self.userView];
    [self.scrollView addSubview:self.serviceView];
    [self.scrollView addSubview:self.orderView];
    [self.scrollView addSubview:self.refundView];
    
    [self requestData];
}

-(void)setIsRefuned:(NSString *)isRefuned{
    _isRefuned = isRefuned;
    UIImage *image = [UIImage imageNamed:@"订单详情-状态背景1"];
    if([isRefuned isEqualToString:@"1"]){
        self.statusLabel.text = @"已退款";
        image = [UIImage imageNamed:@"订单详情-状态背景3"];
        self.refundView.hidden = NO;
        self.scrollView.contentSize = CGSizeMake(Screen_W, kMaxY(self.refundView.frame)+viewPix(50));
    }else{
        self.statusLabel.text = @"已支付";
        image = [UIImage imageNamed:@"订单详情-状态背景1"];
        self.refundView.hidden = YES;
        self.scrollView.contentSize = CGSizeMake(Screen_W, kMaxY(self.orderView.frame)+viewPix(50));
    }
    self.statusView.image = image;
//    self.statusView.image = [image resizableImageWithCapInsets:UIEdgeInsetsMake(image.size.height/2.0, image.size.width/2.0, image.size.height/2.0, image.size.width/2.0) resizingMode:UIImageResizingModeStretch];
}

-(void)requestData{
    [RequestUtil withPOST:@"/doctor/vip/vipinfo" parameters:@{@"vip_id":self.appointId} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
        if(code == 200){
            self.userView.patientInfo = returnData[@"patientinfo"];
            self.serviceView.dataDic = returnData[@"vipinfo"];
            self.orderView.dataDic = returnData[@"orderinfo"];
            self.refundView.dataDic = returnData[@"orderinfo"];
        }
    } error:^(NSError *error) {
        
    }];
}

#pragma mark
#pragma mark ====> 创建控件
-(UIScrollView *)scrollView{
    if(!_scrollView){
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight)];
        _scrollView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    }
    return _scrollView;
}

-(UIImageView *)statusView{
    if(!_statusView){
        _statusView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(41), viewPix(83))];
    }
    return _statusView;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(18, UIFontWeightSemibold) textAlignment:NSTextAlignmentLeft lines:1];
        _statusLabel.frame = CGRectMake(viewPix(39), viewPix(31), viewPix(100), viewPix(20));
    }
    return _statusLabel;
}

-(UIButton *)typeButton{
    if(!_typeButton){
        _typeButton = [UIButton buttonWithTitle:@"订单类型：" titleFont:LGFontWeight(16, UIFontWeightMedium) textColor:@"#333333" imageName:@"订单详情-订单类型"];
        _typeButton.frame = CGRectMake(viewPix(16), kMaxY(self.statusView.frame)+viewPix(16), viewPix(250), viewPix(23));
        _typeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, 0);
    }
    return _typeButton;
}

-(LGOrderUserInfoView *)userView{
    if(!_userView){
        _userView = [[LGOrderUserInfoView alloc]initWithFrame:CGRectMake(viewPix(16), kMaxY(self.typeButton.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(90))];
        [_userView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _userView.backgroundColor = [UIColor whiteColor];
    }
    return _userView;
}

-(LGServiceOrderView *)serviceView{
    if(!_serviceView){
        _serviceView = [[LGServiceOrderView alloc] initWithFrame:CGRectMake(viewPix(16), kMaxY(self.userView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(164))];
        [_serviceView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _serviceView.backgroundColor = [UIColor whiteColor];
        _serviceView.type = @"sevice";
        
    }
    return _serviceView;
}

-(LGServiceOrderView *)orderView{
    if(!_orderView){
        _orderView = [[LGServiceOrderView alloc] initWithFrame:CGRectMake(viewPix(16), kMaxY(self.serviceView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(199))];
        [_orderView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _orderView.backgroundColor = [UIColor whiteColor];
        _orderView.type = @"order";
        
    }
    return _orderView;
}

-(LGServiceOrderView *)refundView{
    if(!_refundView){
        _refundView = [[LGServiceOrderView alloc] initWithFrame:CGRectMake(viewPix(16), kMaxY(self.orderView.frame)+viewPix(16), Screen_W-viewPix(32), viewPix(164))];
        [_refundView setShadoWithColor:@"#B2BDC7" offset:CGSizeMake(0, 2) opacity:0.15 radius:8];
        _refundView.backgroundColor = [UIColor whiteColor];
        _refundView.type = @"refund";
        
    }
    return _refundView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
